package action.plan;

import org.springframework.security.context.SecurityContextHolder;

import persistence.model.TdfkfaPrjPsyj;
import service.PlanService;

import com.opensymphony.xwork2.ActionSupport;

import constant.ServiceConstants;

public class OwnJudgingPlanResultAction extends ActionSupport {

    private static final long serialVersionUID = 1L;

    private PlanService planService;

    private Integer planId;

    private TdfkfaPrjPsyj psyj;

    private String returnCode;

    public String present() throws Exception {
        return SUCCESS;
    }

    public String saveResult() throws Exception {

        String username = SecurityContextHolder.getContext().getAuthentication().getName();
        int ret = planService.savePlanResult(psyj, username);
        if (ret == ServiceConstants.SUCCESS) {
            returnCode = "success";
        } else {
            returnCode = "failure";
        }
        return SUCCESS;
    }

    public String submitResult() throws Exception {

        String username = SecurityContextHolder.getContext().getAuthentication().getName();
        int ret = planService.submitPlanResult(planId, username);
        if (ret == ServiceConstants.SUCCESS) {
            returnCode = "success";
        } else {
            returnCode = "failure";
        }
        return SUCCESS;
    }

    public Integer getPlanId() {
        return planId;
    }

    public void setPlanId(Integer planId) {
        this.planId = planId;
    }

    public void setPlanService(PlanService planService) {
        this.planService = planService;
    }

    public TdfkfaPrjPsyj getPsyj() {
        return psyj;
    }

    public void setPsyj(TdfkfaPrjPsyj psyj) {
        this.psyj = psyj;
    }

    public String getReturnCode() {
        return returnCode;
    }

}
